<?php

/* Author: tbloc@cantho.gov.vn */

class Hoa_hong {

//Properties
    private $LHH_ID;
    private $TRUONG_ID;
    private $TIEN_MAT;
    private $PHAN_TRAM;
    private $IS_ACTIVE;

//properties set get 
    public function setLHH_ID($LHH_ID) {
        $this->LHH_ID = $LHH_ID;
    }

    public function getLHH_ID() {
        return $this->LHH_ID;
    }

    public function setTRUONG_ID($TRUONG_ID) {
        $this->TRUONG_ID = $TRUONG_ID;
    }

    public function getTRUONG_ID() {
        return $this->TRUONG_ID;
    }

    public function setTIEN_MAT($TIEN_MAT) {
        $this->TIEN_MAT = $TIEN_MAT;
    }

    public function getTIEN_MAT() {
        return $this->TIEN_MAT;
    }

    public function setPHAN_TRAM($PHAN_TRAM) {
        $this->PHAN_TRAM = $PHAN_TRAM;
    }

    public function getPHAN_TRAM() {
        return $this->PHAN_TRAM;
    }

    public function setIS_ACTIVE($IS_ACTIVE) {
        $this->IS_ACTIVE = $IS_ACTIVE;
    }

    public function getIS_ACTIVE() {
        return $this->IS_ACTIVE;
    }

//crud methods
    public function insert($db = null) {
        if ($db != null) {
            $sql = "INSERT INTO `hoa_hong`(                        
			`LHH_ID`, 
				`TRUONG_ID`, 
				`TIEN_MAT`, 
				`PHAN_TRAM`, 
				`IS_ACTIVE` 
		)
	VALUES(
    		:LHH_ID, 
	    		:TRUONG_ID, 
	    		:TIEN_MAT, 
	    		:PHAN_TRAM, 
	    		:IS_ACTIVE 
	    );";
            $parameters = array(
                ":LHH_ID",
                ":TRUONG_ID",
                ":TIEN_MAT",
                ":PHAN_TRAM",
                ":IS_ACTIVE"
            );
            $values = array(
                $this->getLHH_ID(),
                $this->getTRUONG_ID(),
                0,
                0,
                1
            );
            $types = array(
                PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_INT //Kiem tra lai kieu du lieu nhe
            );
            $lastInsertID = $db->executeNonQuery($sql, $parameters, $values, $types, true);
            $this->setTRUONG_ID($lastInsertID);
        }
    }

    public function delete($db = null) {
        if ($db != null) {
            $sql = "DELETE FROM `hoa_hong`
	                where `TRUONG_ID` = :TRUONG_ID";
            $parameters = array(":TRUONG_ID");
            $values = array($this->getTRUONG_ID());
            $types = array(PDO::PARAM_INT); //Kiem tra lai kieu du lieu nhe
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function update($db = null) {
        if ($db != null) {
            $sql = "UPDATE `hoa_hong` SET 
			`LHH_ID`=:LHH_ID,
				`TRUONG_ID`=:TRUONG_ID,
				`TIEN_MAT`=:TIEN_MAT,
				`PHAN_TRAM`=:PHAN_TRAM,
				`IS_ACTIVE`=:IS_ACTIVE
			WHERE `TRUONG_ID` = :TRUONG_ID;";
            $parameters = array(
                ":LHH_ID",
                ":TRUONG_ID",
                ":TIEN_MAT",
                ":PHAN_TRAM",
                ":IS_ACTIVE"
            );
            // Kiem tra dau , nhe
            $values = array(
                $this->getLHH_ID(),
                $this->getTRUONG_ID(),
                $this->getTIEN_MAT(),
                $this->getPHAN_TRAM(),
                $this->getIS_ACTIVE()
            );
            $types = array(
                PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_INT, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_STR, //Kiem tra lai kieu du lieu nhe
                PDO::PARAM_INT //Kiem tra lai kieu du lieu nhe
            );
            $result = $db->executeNonQuery($sql, $parameters, $values, $types);
            return $result;
        }
    }

    public function getByID($id, $truong, $db = null) {
        if ($db != null) {
            $sql = "SELECT
			`LHH_ID`,
				`TRUONG_ID`,
				`TIEN_MAT`,
				`PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `hoa_hong` WHERE `LHH_ID`=:LHH_ID AND `TRUONG_ID`=:TRUONG_ID AND `is_active`=1;";
            $parameters = array(":LHH_ID", ":TRUONG_ID");
            $values = array($id,$truong);
            $types = array(PDO::PARAM_INT,PDO::PARAM_INT); //kiem tra lai kieu du lieu nhe
            $rows = $db->executeQuery($sql, $parameters, $values, $types);
            if ($rows != null) {
                $row = $rows->fetch();
                $hoahong=new Hoa_hong();
                $hoahong->setLHH_ID($row->LHH_ID);
                $hoahong->setTRUONG_ID($row->TRUONG_ID);
                $hoahong->setTIEN_MAT($row->TIEN_MAT);
                $hoahong->setPHAN_TRAM($row->PHAN_TRAM);
                $hoahong->setIS_ACTIVE($row->IS_ACTIVE);
                 return $hoahong;
            }
           
        }
    }

    
     public function getByID_($truong, $db = null) {
        if ($db != null) {
            $sql = "SELECT
			`LHH_ID`,
				`TRUONG_ID`,
				`TIEN_MAT`,
				`PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `hoa_hong` WHERE  `TRUONG_ID`=:TRUONG_ID AND `is_active`=1;";
            $parameters = array(":TRUONG_ID");
            $values = array($truong);
            $types = array(PDO::PARAM_INT,PDO::PARAM_INT); //kiem tra lai kieu du lieu nhe
            $rows = $db->executeQuery($sql, $parameters, $values, $types);
           $objects = array();
            if ($rows != null) {
                while ($row = $rows->fetch()) {
                    $obj = new Hoa_hong();
                    $obj->setLHH_ID($row->LHH_ID);
                    $obj->setTRUONG_ID($row->TRUONG_ID);
                    $obj->setTIEN_MAT($row->TIEN_MAT);
                    $obj->setPHAN_TRAM($row->PHAN_TRAM);
                    $obj->setIS_ACTIVE($row->IS_ACTIVE);
                    $objects[] = $obj;
                }
                return $objects;
            }
           
        }
    }
    
    
    public function getArrayByID($id,$db = null) {
        if ($db != null) {
            $sql = "SELECT
			`LHH_ID`,
				`TRUONG_ID`,
				`TIEN_MAT`,
				`PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `hoa_hong` WHERE `TRUONG_ID`=:TRUONG_ID AND `is_active`=1;";
            $parameters = array(":TRUONG_ID");
            $values = array($id);
            $types = array(PDO::PARAM_INT); //kiem tra lai kieu du lieu nhe
            $rows = $db->executeQuery($sql, $parameters, $values, $types);
            $objects = array();
            if ($rows != null) {
                while ($row = $rows->fetch()) {
                    $obj = new Hoa_hong();
                    $obj->setLHH_ID($row->LHH_ID);
                    $obj->setTRUONG_ID($row->TRUONG_ID);
                    $obj->setTIEN_MAT($row->TIEN_MAT);
                    $obj->setPHAN_TRAM($row->PHAN_TRAM);
                    $obj->setIS_ACTIVE($row->IS_ACTIVE);
                    $objects[] = $obj;
                }
                return $objects;
            }
        }
    }
    
    public function getList($db = null) {
        if ($db != null) {
            $sql = "SELECT
			`LHH_ID`,
				`TRUONG_ID`,
				`TIEN_MAT`,
				`PHAN_TRAM`,
				`IS_ACTIVE`
			FROM `hoa_hong` WHERE `is_active`=1;";
            $rows = $db->executeQuery($sql);
            $objects = array();
            if ($rows != null) {
                while ($row = $rows->fetch()) {
                    $obj = new Hoa_hong();
                    $obj->setLHH_ID($row->LHH_ID);
                    $obj->setTRUONG_ID($row->TRUONG_ID);
                    $obj->setTIEN_MAT($row->TIEN_MAT);
                    $obj->setPHAN_TRAM($row->PHAN_TRAM);
                    $obj->setIS_ACTIVE($row->IS_ACTIVE);
                    $objects[] = $obj;
                }
                return $objects;
            }
        }
    }

}
?>

